package com.itheima.wed.servlet;

import com.itheima.domain.User;
import com.itheima.servicce.UserService;
import com.itheima.servicce.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/findUserServlet")
public class FindUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1. 获取修改用户的id
        String uid = request.getParameter("id");
        //2. 调用service查询,返回User对象
        UserService service = new UserServiceImpl();
        User user = service.findById(uid);
        //3. 存入request域中,转发到update.jsp
        request.setAttribute("user",user);
        request.getRequestDispatcher("update.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}